package com.yuanfeng.base.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.base.dto.BaseSystemPlatformNavDTO;
import com.yuanfeng.base.entity.BaseSystemPlatformNavEntity;
import com.yuanfeng.base.mapper.BaseSystemPlatformNavMapper;
import com.yuanfeng.base.service.BaseSystemPlatformNavService;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 页面导航表(BaseSystemPlatformNav)
 *
 * @since 2023-03-28 17:29:45
 */
@Service
public class BaseSystemPlatformNavServiceImpl extends ServiceImpl<BaseSystemPlatformNavMapper, BaseSystemPlatformNavEntity>
        implements BaseSystemPlatformNavService {


    @Override
    public ResponseResult updatePlatformNav(BaseSystemPlatformNavDTO baseSystemPlatformNavDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(baseSystemPlatformNavDto.getToken());
        if (null != userInfo) {
            if (null == baseSystemPlatformNavDto.getNavId()) {
                this.baseMapper.insertPlatformNav(baseSystemPlatformNavDto);
            } else {
                this.baseMapper.updatePlatformNav(baseSystemPlatformNavDto);
            }
            return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult deletePlatformNav(BaseSystemPlatformNavDTO baseSystemPlatformNavDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(baseSystemPlatformNavDto.getToken());
        if (null != userInfo) {
            this.baseMapper.deleteById(baseSystemPlatformNavDto.getNavId());
            return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult querySystemPlatformNavById(BaseSystemPlatformNavDTO baseSystemPlatformNavDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(baseSystemPlatformNavDto.getToken());
        if (null != userInfo) {
            BaseSystemPlatformNavEntity baseSystemPlatformNaventity = this.baseMapper.selectById(baseSystemPlatformNavDto.getNavId());
            return ResponseResult.success(baseSystemPlatformNaventity);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }

    @Override
    public ResponseResult querySystemPlatformNavList(BaseSystemPlatformNavDTO baseSystemPlatformNavDto) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(baseSystemPlatformNavDto.getToken());
        if (null != userInfo) {
            List<BaseSystemPlatformNavEntity> baseSystemPlatformNavEntities = this.baseMapper.selectList(new LambdaQueryWrapper<BaseSystemPlatformNavEntity>()
                                                                             .eq(BaseSystemPlatformNavEntity::getNavProperty,baseSystemPlatformNavDto.getNavProperty())
                                                                             .orderByAsc(BaseSystemPlatformNavEntity::getNavDisplayorder));
            return ResponseResult.success(baseSystemPlatformNavEntities);
        }
        return ResponseResult.fail(BizCodeEnume.TOKEN_IS_ILLEGAL);
    }


}

